package cn.sc.summer.gateway.handler;

import cn.sc.summer.constant.model.Result;
import cn.sc.summer.gateway.exception.CommonException;
import cn.sc.summer.gateway.exception.NotFindGirlFriendException;
import cn.sc.summer.gateway.exception.NotFindMoneyException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 类名：全局异常捕获
 *
 * @author a-xin
 * @date 2:29 PM
 */
@Slf4j
@RestControllerAdvice
public class ExceptionHandler {

    @ResponseBody
    @org.springframework.web.bind.annotation.ExceptionHandler(RuntimeException.class)
    public Result<String> exceptionResult(RuntimeException e) {
        e.printStackTrace();
        return Result.fail(e.getMessage());
    }

    @ResponseBody
    @org.springframework.web.bind.annotation.ExceptionHandler(value = CommonException.class)
    private Result<String> customExceptionHandler(CommonException e) {
        e.printStackTrace();
        return Result.fail(e.getCode(), e.getMessage());
    }

    @ResponseBody
    @org.springframework.web.bind.annotation.ExceptionHandler(value = NotFindGirlFriendException.class)
    private Result<String> customExceptionHandler(NotFindGirlFriendException e) {
        e.printStackTrace();
        return Result.fail(e.getCode(), e.getMessage());
    }

    @ResponseBody
    @org.springframework.web.bind.annotation.ExceptionHandler(value = NotFindMoneyException.class)
    private Result<String> customExceptionHandler(NotFindMoneyException e) {
        e.printStackTrace();
        return Result.fail(e.getCode(), e.getMessage());
    }

}
